<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker
          clearable
          v-model="queryParams.startDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="申请人" prop="applicatName">
        <el-input
          v-model="queryParams.applicatName"
          placeholder="申请人"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>

<!--      <el-form-item label="所属军区" prop="theirMilitary">-->
<!--        <el-select-->
<!--          v-model="queryParams.theirMilitary"-->
<!--          placeholder="请选择所属军区"-->
<!--          @change="handleQuery"-->
<!--        >-->
<!--          <el-option-->
<!--            v-for="dict in belong_military_region"-->
<!--            :key="dict.value"-->
<!--            :label="dict.label"-->
<!--            :value="dict.value"-->
<!--          ></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->

      <el-form-item label="门店" prop="signBillDept">
        <el-input
          v-model="queryParams.signBillDept"
          placeholder="门店"
          clearable
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>

          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['business:offlineRefunded:export']"
          >导出</el-button>


          <el-button
            type="info"
            plain
            icon="Upload"
            @click="handleImport"
          >导入</el-button>

      </el-form-item>
    </el-form>

<!--    <el-row :gutter="10" class="mb8">-->
<!--&lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
<!--&lt;!&ndash;        <el-button&ndash;&gt;-->
<!--&lt;!&ndash;          type="primary"&ndash;&gt;-->
<!--&lt;!&ndash;          plain&ndash;&gt;-->
<!--&lt;!&ndash;          icon="Plus"&ndash;&gt;-->
<!--&lt;!&ndash;          @click="handleAdd"&ndash;&gt;-->
<!--&lt;!&ndash;          v-hasPermi="['business:offlineRefunded:add']"&ndash;&gt;-->
<!--&lt;!&ndash;        >新增</el-button>&ndash;&gt;-->
<!--&lt;!&ndash;      </el-col>&ndash;&gt;-->
<!--&lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
<!--&lt;!&ndash;        <el-button&ndash;&gt;-->
<!--&lt;!&ndash;          type="success"&ndash;&gt;-->
<!--&lt;!&ndash;          plain&ndash;&gt;-->
<!--&lt;!&ndash;          icon="Edit"&ndash;&gt;-->
<!--&lt;!&ndash;          :disabled="single"&ndash;&gt;-->
<!--&lt;!&ndash;          @click="handleUpdate"&ndash;&gt;-->
<!--&lt;!&ndash;          v-hasPermi="['business:offlineRefunded:edit']"&ndash;&gt;-->
<!--&lt;!&ndash;        >修改</el-button>&ndash;&gt;-->
<!--&lt;!&ndash;      </el-col>&ndash;&gt;-->
<!--&lt;!&ndash;      <el-col :span="1.5">&ndash;&gt;-->
<!--&lt;!&ndash;        <el-button&ndash;&gt;-->
<!--&lt;!&ndash;          type="danger"&ndash;&gt;-->
<!--&lt;!&ndash;          plain&ndash;&gt;-->
<!--&lt;!&ndash;          icon="Delete"&ndash;&gt;-->
<!--&lt;!&ndash;          :disabled="multiple"&ndash;&gt;-->
<!--&lt;!&ndash;          @click="handleDelete"&ndash;&gt;-->
<!--&lt;!&ndash;          v-hasPermi="['business:offlineRefunded:remove']"&ndash;&gt;-->
<!--&lt;!&ndash;        >删除</el-button>&ndash;&gt;-->
<!--&lt;!&ndash;      </el-col>&ndash;&gt;-->

<!--      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>-->
<!--    </el-row>-->

    <el-table v-loading="loading" :data="offlineRefundedList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="" align="center" prop="id" v-if="true"/>-->
      <el-table-column label="审批编号" align="center" prop="approvalCode" />
      <el-table-column label="审批详情" align="center" prop="approvalDetails" show-overflow-tooltip />
      <el-table-column label="提交时间" align="center" prop="submitTime" width="160" />
      <el-table-column label="完成时间" align="center" prop="completeTime" width="160"/>
      <el-table-column label="申请人" align="center" prop="applicatName" />
      <el-table-column label="申请人部门" align="center" prop="applicatDept" width="160"/>
      <el-table-column label="申请人账号" align="center" prop="applicatAccount" width="160"/>
      <el-table-column label="会员姓名" align="center" prop="memberName" />
      <el-table-column label="签单所属部门" align="center" prop="signBillDept" width="160"/>
      <el-table-column label="退款分类" align="center" prop="refundClassification" />
      <el-table-column label="美容美发" align="center" prop="hairdressing" />
      <el-table-column label="退款产品" align="center" prop="refundProduct" />
      <el-table-column label="产品退款类型" align="center" prop="productRefundType" width="160"/>
      <el-table-column label="服务退款类型" align="center" prop="serviceRefundType" width="160"/>
      <el-table-column label="是否修剪" align="center" prop="whetherTrim" />
      <el-table-column label="会员卡类型" align="center" prop="memberType" width="160"/>
      <el-table-column label="退货产品退到：" align="center" prop="refundProductArrive" width="160"/>
      <el-table-column label="此笔退款收款方式：" align="center" prop="refundMode" width="160"/>
      <el-table-column label="此笔退款单号后6位" align="center" prop="refundOrderNo" width="160"/>
      <el-table-column label="此笔退款收款时间" align="center" prop="refundReceiptTime" width="160" />
      <el-table-column label="此笔退款收款金额：" align="center" prop="refundReceiptPrice" width="160"/>
      <el-table-column label="退款事由：" align="center" prop="refundReasons" show-overflow-tooltip width="160"/>
      <el-table-column label="客服对接人：" align="center" prop="serviceName" width="160"/>
      <el-table-column label="服务老师" align="center" prop="serverTeacherName" />
      <el-table-column label="附件" align="center" prop="attachment" />
      <el-table-column label="银行卡支付信息-收款人开户行" align="center" prop="bankAccount" width="200"/>
      <el-table-column label="银行卡支付信息-收款人全称：" align="center" prop="bankPayeeName" width="200"/>
      <el-table-column label="银行卡支付信息-收款人账号：" align="center" prop="bankPaymentAccount" width="200"/>
      <el-table-column label="银行卡支付信息-打款金额：" align="center" prop="bankPaymentPrice" width="200"/>
      <el-table-column label="银行卡支付信息-金额大写" align="center" prop="bankPaymentCapital" width="200"/>
      <el-table-column label="当前审批状态" align="center" prop="approvalStatus" width="160"/>
      <el-table-column label="审批流程" align="center" prop="approvalProcess" show-overflow-tooltip />
      <el-table-column label="备注" align="center" prop="remake" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
<!--          <template #default="scope">-->
<!--              <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:offlineRefunded:edit']">修改</el-button>-->
<!--              <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:offlineRefunded:remove']">删除</el-button>-->
<!--          </template>-->
<!--      </el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 用户导入对话框 -->
    <el-dialog
      :title="upload.title"
      v-model="upload.open"
      width="400px"
      append-to-body
    >
      <el-upload
        ref="uploadRef"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <el-icon class="el-icon--upload"><upload-filled /></el-icon>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <template #tip>
          <div class="el-upload__tip text-center">
<!--            <div class="el-upload__tip">-->
<!--              <el-checkbox-->
<!--                v-model="upload.updateSupport"-->
<!--              />是否更新已经存在的用户数据-->
<!--            </div>-->
            <span>仅允许导入xls、xlsx格式文件。</span>
<!--            <el-link-->
<!--              type="primary"-->
<!--              :underline="false"-->
<!--              style="font-size: 12px; vertical-align: baseline"-->
<!--              @click="importTemplate"-->
<!--            >下载模板</el-link>-->
          </div>
        </template>
      </el-upload>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitFileForm">确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="OfflineRefunded">
import { listOfflineRefunded, getOfflineRefunded, delOfflineRefunded, addOfflineRefunded, updateOfflineRefunded } from "@/api/business/offlineRefunded";
import { getToken } from "@/utils/auth";
const { proxy } = getCurrentInstance();
const { sys_teacher_tag, belong_military_region } = proxy.useDict(
  "sys_teacher_tag",
  "belong_military_region"
);
const offlineRefundedList = ref([]);
const open = ref(false);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
/*** 用户导入参数 */
const upload = reactive({
  // 是否显示弹出层（用户导入）
  open: false,
  // 弹出层标题（用户导入）
  title: "",
  // 是否禁用上传
  isUploading: false,
  // 是否更新已经存在的用户数据
  updateSupport: 0,
  // 设置上传的请求头部
  headers: { Authorization: "Bearer " + getToken() },
  // 上传的地址
  url: import.meta.env.VITE_APP_BASE_API + "/business/offlineRefunded/importData",
});
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    approvalCode: undefined,
    approvalDetails: undefined,
    submitTime: undefined,
    completeTime: undefined,
    applicatName: undefined,
    applicatDept: undefined,
    applicatAccount: undefined,
    memberName: undefined,
    signBillDept: undefined,
    refundClassification: undefined,
    hairdressing: undefined,
    refundProduct: undefined,
    productRefundType: undefined,
    serviceRefundType: undefined,
    whetherTrim: undefined,
    memberType: undefined,
    refundProductArrive: undefined,
    refundMode: undefined,
    refundOrderNo: undefined,
    refundReceiptTime: undefined,
    refundReceiptPrice: undefined,
    refundReasons: undefined,
    serviceName: undefined,
    serverTeacherName: undefined,
    attachment: undefined,
    bankAccount: undefined,
    bankPayeeName: undefined,
    bankPaymentAccount: undefined,
    bankPaymentPrice: undefined,
    bankPaymentCapital: undefined,
    approvalStatus: undefined,
    approvalProcess: undefined,
    remake: undefined,
  },
  rules: {
    id: [
      { required: true, message: "不能为空", trigger: "blur" }
    ],
    approvalCode: [
      { required: true, message: "审批编号不能为空", trigger: "blur" }
    ],
    approvalDetails: [
      { required: true, message: "审批详情不能为空", trigger: "blur" }
    ],
    submitTime: [
      { required: true, message: "提交时间不能为空", trigger: "blur" }
    ],
    completeTime: [
      { required: true, message: "完成时间不能为空", trigger: "blur" }
    ],
    applicatName: [
      { required: true, message: "申请人不能为空", trigger: "blur" }
    ],
    applicatDept: [
      { required: true, message: "申请人部门不能为空", trigger: "blur" }
    ],
    applicatAccount: [
      { required: true, message: "申请人账号不能为空", trigger: "blur" }
    ],
    memberName: [
      { required: true, message: "会员姓名不能为空", trigger: "blur" }
    ],
    signBillDept: [
      { required: true, message: "签单所属部门不能为空", trigger: "blur" }
    ],
    refundClassification: [
      { required: true, message: "退款分类不能为空", trigger: "blur" }
    ],
    hairdressing: [
      { required: true, message: "美容美发不能为空", trigger: "blur" }
    ],
    refundProduct: [
      { required: true, message: "退款产品不能为空", trigger: "blur" }
    ],
    productRefundType: [
      { required: true, message: "产品退款类型不能为空", trigger: "change" }
    ],
    serviceRefundType: [
      { required: true, message: "服务退款类型不能为空", trigger: "change" }
    ],
    whetherTrim: [
      { required: true, message: "是否修剪不能为空", trigger: "blur" }
    ],
    memberType: [
      { required: true, message: "会员卡类型不能为空", trigger: "change" }
    ],
    refundProductArrive: [
      { required: true, message: "退货产品退到：不能为空", trigger: "blur" }
    ],
    refundMode: [
      { required: true, message: "此笔退款收款方式：不能为空", trigger: "blur" }
    ],
    refundOrderNo: [
      { required: true, message: "此笔退款单号后6位不能为空", trigger: "blur" }
    ],
    refundReceiptTime: [
      { required: true, message: "此笔退款收款时间不能为空", trigger: "blur" }
    ],
    refundReceiptPrice: [
      { required: true, message: "此笔退款收款金额：不能为空", trigger: "blur" }
    ],
    refundReasons: [
      { required: true, message: "退款事由：不能为空", trigger: "blur" }
    ],
    serviceName: [
      { required: true, message: "客服对接人：不能为空", trigger: "blur" }
    ],
    serverTeacherName: [
      { required: true, message: "服务老师不能为空", trigger: "blur" }
    ],
    attachment: [
      { required: true, message: "附件不能为空", trigger: "blur" }
    ],
    bankAccount: [
      { required: true, message: "银行卡支付信息-收款人开户行不能为空", trigger: "blur" }
    ],
    bankPayeeName: [
      { required: true, message: "银行卡支付信息-收款人全称：不能为空", trigger: "blur" }
    ],
    bankPaymentAccount: [
      { required: true, message: "银行卡支付信息-收款人账号：不能为空", trigger: "blur" }
    ],
    bankPaymentPrice: [
      { required: true, message: "银行卡支付信息-打款金额：不能为空", trigger: "blur" }
    ],
    bankPaymentCapital: [
      { required: true, message: "银行卡支付信息-金额大写不能为空", trigger: "blur" }
    ],
    approvalStatus: [
      { required: true, message: "当前审批状态不能为空", trigger: "change" }
    ],
    approvalProcess: [
      { required: true, message: "审批流程不能为空", trigger: "blur" }
    ],
    remake: [
      { required: true, message: "备注不能为空", trigger: "blur" }
    ],
  }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询线下退款信息列表 */
function getList() {
  loading.value = true;
  listOfflineRefunded(queryParams.value).then(response => {
    offlineRefundedList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    approvalCode: null,
    approvalDetails: null,
    submitTime: null,
    completeTime: null,
    applicatName: null,
    applicatDept: null,
    applicatAccount: null,
    memberName: null,
    signBillDept: null,
    refundClassification: null,
    hairdressing: null,
    refundProduct: null,
    productRefundType: null,
    serviceRefundType: null,
    whetherTrim: null,
    memberType: null,
    refundProductArrive: null,
    refundMode: null,
    refundOrderNo: null,
    refundReceiptTime: null,
    refundReceiptPrice: null,
    refundReasons: null,
    serviceName: null,
    serverTeacherName: null,
    attachment: null,
    bankAccount: null,
    bankPayeeName: null,
    bankPaymentAccount: null,
    bankPaymentPrice: null,
    bankPaymentCapital: null,
    approvalStatus: null,
    approvalProcess: null,
    remake: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null,
    delFlag: null
  };
  proxy.resetForm("offlineRefundedRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加线下退款信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  loading.value = true
  reset();
  const _id = row.id || ids.value
  getOfflineRefunded(_id).then(response => {
    loading.value = false;
    form.value = response.data;
    open.value = true;
    title.value = "修改线下退款信息";
  });
}

/** 导入按钮操作 */
function handleImport() {
  upload.title = "用户导入";
  upload.open = true;
}
/** 下载模板操作 */
function importTemplate() {
  proxy.download(
    "system/user/importTemplate",
    {},
    `user_template_${new Date().getTime()}.xlsx`
  );
}
/**文件上传中处理 */
const handleFileUploadProgress = (event, file, fileList) => {
  upload.isUploading = true;
};
/** 文件上传成功处理 */
const handleFileSuccess = (response, file, fileList) => {
  upload.open = false;
  upload.isUploading = false;
  proxy.$refs["uploadRef"].handleRemove(file);
  proxy.$alert(
    "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
    response.msg +
    "</div>",
    "导入结果",
    { dangerouslyUseHTMLString: true }
  );
  getList();
};
/** 提交上传文件 */
function submitFileForm() {
  proxy.$refs["uploadRef"].submit();
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["offlineRefundedRef"].validate(valid => {
    if (valid) {
      buttonLoading.value = true;
      if (form.value.id != null) {
        updateOfflineRefunded(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      } else {
        addOfflineRefunded(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        }).finally(() => {
          buttonLoading.value = false;
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value;
  proxy.$modal.confirm('是否确认删除线下退款信息编号为"' + _ids + '"的数据项？').then(function() {
    loading.value = true;
    return delOfflineRefunded(_ids);
  }).then(() => {
    loading.value = true;
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  }).finally(() => {
    loading.value = false;
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('business/offlineRefunded/export', {
    ...queryParams.value
  }, `offlineRefunded_${new Date().getTime()}.xlsx`)
}

getList();
</script>
